package com.atguigu.tingshu.account.service.impl;

import com.atguigu.tingshu.account.mapper.UserAccountMapper;
import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author sun
 */
@Slf4j
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements UserAccountService {

	@Resource
	private UserAccountMapper userAccountMapper;

	/**
	 * 初始化用户账户
	 *
	 * @param userId 用户id
	 */
	@Override
	public void initAccount(Long userId) {
		BigDecimal newBigDecimal = new BigDecimal(0);
		UserAccount userAccount = UserAccount.builder()
				.userId(userId)
				.totalAmount(newBigDecimal)
				.totalIncomeAmount(newBigDecimal)
				.totalPayAmount(newBigDecimal)
				.availableAmount(newBigDecimal)
				.lockAmount(newBigDecimal)
				.build();

		userAccountMapper.insert(userAccount);

	}
}
